﻿#include "BoxlineSettingWid.h"
#include "ui_BoxlineSettingWid.h"
#include "../component/componentmanager.h"


BoxlineSettingWid::BoxlineSettingWid(QWidget* parent)
	: QWidget(parent)
	, ui(new Ui::BoxlineSettingWid())
{
	ui->setupUi(this);
	setStyleSheet("font: 12pt \"Agency FB\"");

	QHBoxLayout* lay = new QHBoxLayout(ui->groupBox);
	m_base = new PositionSettingWid(this);
	lay->addWidget(m_base);
	auto algm = component->GetComponent(Component::component_algorithm);
	if (algm) {
		QByteArray input, output;
		if (algm->ExcuteCmd(1, input, output)) {
			QString name = output;
			QStringList names = name.split('-');
			ui->comboBox->clear();
			ui->comboBox->addItems(names);
		}
	}
}

BoxlineSettingWid::~BoxlineSettingWid()
{
	delete ui;
}

void BoxlineSettingWid::Init(const BoxlineCfg& cfg)
{
	ui->lineEdit->setText(cfg.id());
	ui->comboBox->setCurrentText(cfg.alg());
	ui->comboBox_2->setCurrentIndex(cfg.dir());
	ui->comboBox_3->setCurrentIndex(cfg.type());
	ui->lineEdit_2->setText(cfg.di());
	ui->lineEdit_3->setText(cfg.dival());
	m_base->Init(cfg.base());
}
BoxlineCfg BoxlineSettingWid::GetCfg()
{
	BoxlineCfg cfg = {};
	cfg.base = m_base->GetPositon();
	cfg.id = ui->lineEdit->text();
	cfg.posid = 0;
	cfg.alg = ui->comboBox->currentText();
	cfg.dir = ui->comboBox_2->currentIndex();
	cfg.type = ui->comboBox_3->currentIndex();
	cfg.di = ui->lineEdit_2->text();
	cfg.dival = ui->lineEdit_3->text();
	return cfg;
}
